SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE [dbo].gspCustomerInfo_SEARCH
(
@customerInfoId int = null,
@accountId int = null,
@cityId int = null,
@paymentTypeId int = null,
@firstName nvarchar(128) = null,
@middleName nvarchar(128) = null,
@lastName nvarchar(128) = null,
@postIndex int = null,
@postAddress nvarchar(256) = null,
@phone nvarchar(40) = null,
@icq int = null,
@skype nvarchar(256) = null,
@email nvarchar(256) = null,
@createdDate datetime = null,
@lastModifiedDate datetime = null
)
AS

SELECT
  *
FROM
  [dbo].[CustomerInfo]
WHERE
  (@customerInfoId IS NULL OR [CustomerInfoId] = @customerInfoId)
AND
  (@accountId IS NULL OR [AccountId] = @accountId)
AND
  (@cityId IS NULL OR [CityId] = @cityId)
AND
  (@paymentTypeId IS NULL OR [PaymentTypeId] = @paymentTypeId)
AND
  (@firstName IS NULL OR @firstName = '' OR [FirstName] LIKE @firstName + '%')
AND
  (@middleName IS NULL OR @middleName = '' OR [MiddleName] LIKE @middleName + '%')
AND
  (@lastName IS NULL OR @lastName = '' OR [LastName] LIKE @lastName + '%')
AND
  (@postIndex IS NULL OR [PostIndex] = @postIndex)
AND
  (@postAddress IS NULL OR @postAddress = '' OR [PostAddress] LIKE @postAddress + '%')
AND
  (@phone IS NULL OR @phone = '' OR [Phone] LIKE @phone + '%')
AND
  (@icq IS NULL OR [Icq] = @icq)
AND
  (@skype IS NULL OR @skype = '' OR [Skype] LIKE @skype + '%')
AND
  (@email IS NULL OR @email = '' OR [Email] LIKE @email + '%')
AND
  (@createdDate IS NULL OR [CreatedDate] = @createdDate)
AND
  (@lastModifiedDate IS NULL OR [LastModifiedDate] = @lastModifiedDate)


GO
